<?php

namespace App\Console\Commands;

use App\Models\Article;
use App\Models\Circle;
use App\Models\CircleCategoryRelate;
use App\Models\Comment;
use App\Models\Star;
use App\Models\User;
use App\Mongo\ArticleMon;
use App\Mongo\CircleMon;
use Illuminate\Console\Command;
use YangJiSen\CacheUserProvider\CacheForget;

class TestCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        User::where('black_at', '2222-01-01 00:00:00')->chunkById(1000, function ($list) {
            foreach ($list as $user) {
                CacheForget::CacheForget($user);
            }
        });
        return;
        Star::chunk(100, function ($list) {
            foreach ($list as $item) {
                if ($item->type == 1) {
                    $article = Article::find($item->entity_id);
                    $item->article_id = $article->id;
                    $item->article_user_id = $article->user_id;
                    $item->child_type = $item->type;
                    $item->save();
                } else {
                    $comment = Comment::find($item->entity_id);
                    if ($comment) {
                        $item->article_id = $comment->entity_id;
                        $item->article_user_id = $comment->entity_user_id;
                        $item->child_type = 4;
                        $item->save();
                    }
                }
            }
        });


        exit;

        Circle::chunk(100, function ($list) {
            foreach ($list as $circle) {
                CircleMon::where('id', $circle->id)->update([
                    'status' => $circle->status
                ]);
            }
        });
        exit;
        exit;
        $arr_id = CircleCategoryRelate::where('circle_category_id', 2)->pluck('circle_id')->all();
        Circle::whereIn('is_area', $arr_id)->chunk(100000, function ($list) {
            foreach ($list as $item) {
                $title = mb_substr($item->title, 0, -3) . '宠友圈';
                $item->title= $title;
                $item->save();
            }
        });
//
//        exit;
        $aa = ArticleMon::whereNotIn('status', [1, 2])->delete();
        var_dump($aa);exit;
        \Log::info('-----------start-user-black-----------------------------');
        Article::chunk(100, function ($list) {
            foreach ($list as $item) {
                ArticleMon::where('id', $item->id)->update([
                    'status' => $item->status
                ]);
            }
        });
        \Log::info('-----------end-user-black-----------------------------');
    }
}
